/**
 * plugin.js
 *
 */

/*global tinymce:true */
tinymce.PluginManager.add('filemanager', function(editor) {

   function showDialog() {
      editor.focus(true);
      var title="File Manager";
      if (typeof editor.settings.filemanager_title !== "undefined" && editor.settings.filemanager_title) {
         title=editor.settings.filemanager_title;
      }

      editor.windowManager.open({
         title: title,
         file: editor.settings.external_filemanager_path+'index.html',
         width: editor.getParam("code_dialog_width", Math.max(Math.min(tinymce.DOM.getViewPort().w - 50, 860),450)),
         height: editor.getParam("code_dialog_height", Math.min(tinymce.DOM.getViewPort().h - 200, 570)),
         inline: 1,
         resizable: true,
         maximizable: true
      });
   }
    
   editor.addButton('filemanager', {
      icon: 'browse',
      tooltip: 'Insert file',
      shortcut: 'Ctrl+E',
      onclick: showDialog
   });
        
   editor.addShortcut('Ctrl+E', '', showDialog);

   editor.addMenuItem('filemanager', {
      icon: 'browse',
      text: 'Insert file',
      shortcut: 'Ctrl+E',
      onclick: showDialog,
      context: 'insert'
   });
   
});
